﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.CRM.Library;
using ZX.CRM.Bussiness;
using ZX.DBModule;
using ZX.Common;
using ZX.SYS.Library;
using ZX.BLL;
using System.IO;

namespace ZX.WebApp.Crm.Deliver
{
    public partial class DeliverMajorStudentInfo : EditUIPage
    {
        private string _minZu = "";
        private string _studentList = "";
        private string _photoUrl = "";
        BCrmDeliverMajor bll = new BCrmDeliverMajor();
        BDatPhraseDetail bllDetail = new BDatPhraseDetail();
        protected void Page_Load(object sender, EventArgs e)
        {
            string _studentId = this.GetStringFromQueryString("id", "");
            IList<V_CrmDeliverMajorInfo> listStudent = bll.GetAllStudentByStudentId(new Guid(_studentId));
            if (listStudent != null && listStudent.Count > 0)
            {
                //民族
                if (listStudent[0].MinZu != "null" && listStudent[0].MinZu != null && listStudent[0].MinZu != "")
                {
                    IList<DatPhraseDetail> _ListMinZu = bllDetail.GetDatPhraseDetailById(new Guid(listStudent[0].MinZu));
                    if (_ListMinZu != null && _ListMinZu.Count > 0)
                    {
                        _minZu = _ListMinZu[0].PhraseText;
                    }
                }

                IList<BaseEntity> _listStudent = new List<BaseEntity>();
                foreach (var _e in listStudent)
                {
                    _listStudent.Add(_e);
                }
                _studentList = _listStudent.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");

                //string strPath = this.imageUrl.Value;
                //if (strPath != "")
                {
                    string strPath = Server.MapPath("~\\" + this.imageUrl.Value);
                    DirectoryInfo di = new DirectoryInfo(strPath);
                    FileInfo[] strFileNames = di.GetFiles();
                    foreach (FileInfo strFileName in strFileNames)
                    {
                        try
                        {
                            string _FileName = strFileName.Name;
                            if (_FileName.EndsWith(".jpg"))
                            {
                                string[] _FileNames = _FileName.Split('_');
                                if (_FileNames.Length <= 1)
                                    continue;
                                if (_FileNames.Length >= 3)
                                {
                                    //ID相同
                                    if (_FileNames[2] == listStudent[0].ID.ToString())
                                    {
                                        _photoUrl = _FileName;
                                        break;
                                    }
                                    //身份证相同
                                    if (_FileNames[1] == listStudent[0].IDCard.Trim())
                                    {
                                        _photoUrl = _FileName;
                                        break;
                                    }
                                }
                                else
                                {
                                    //身份证相同
                                    if (_FileNames[1] == listStudent[0].IDCard.Trim())
                                    {
                                        _photoUrl = _FileName;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
        public string strPhotoUrl
        {
            get { return this._photoUrl; }
        }
        public string strMinZu
        {
            get { return this._minZu; }
        }
        public string strStudentList
        {
            get { return this._studentList; }
        }
    }
}